<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/snowzhao/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/snowzhao/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/snowzhao/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/snowzhao/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/snowzhao/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/snowzhao/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/snowzhao/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="android,">










<meta name="description" content="Android项目开发肯定离不开图片的加载，常见的图片加载样式也就圆图、方图、圆角图、单面圆角其他方图； Android加载图片之前使用imageload加载，现在可能没人使用了吧，应该都使用glide或者Picasso了吧；我自己使用glide封装了一个依赖库，可以实现基本的图片样式加载，先看效果图：  看完效果图来看看使用方法吧： 集成方法：api &amp;#39;com.bintray.libra">
<meta name="keywords" content="android">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 更好用的图片加载库">
<meta property="og:url" content="https://vincent_zyt.gitee.io/snowzhao/2019/12/02/Android-更好用的图片加载库/index.html">
<meta property="og:site_name" content="snowzhao博客">
<meta property="og:description" content="Android项目开发肯定离不开图片的加载，常见的图片加载样式也就圆图、方图、圆角图、单面圆角其他方图； Android加载图片之前使用imageload加载，现在可能没人使用了吧，应该都使用glide或者Picasso了吧；我自己使用glide封装了一个依赖库，可以实现基本的图片样式加载，先看效果图：  看完效果图来看看使用方法吧： 集成方法：api &amp;#39;com.bintray.libra">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20191202154028339.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxNzk2NjUx,size_16,color_FFFFFF,t_70#pic_center">
<meta property="og:updated_time" content="2019-12-02T07:43:43.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android 更好用的图片加载库">
<meta name="twitter:description" content="Android项目开发肯定离不开图片的加载，常见的图片加载样式也就圆图、方图、圆角图、单面圆角其他方图； Android加载图片之前使用imageload加载，现在可能没人使用了吧，应该都使用glide或者Picasso了吧；我自己使用glide封装了一个依赖库，可以实现基本的图片样式加载，先看效果图：  看完效果图来看看使用方法吧： 集成方法：api &amp;#39;com.bintray.libra">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20191202154028339.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxNzk2NjUx,size_16,color_FFFFFF,t_70#pic_center">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/snowzhao/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://vincent_zyt.gitee.io/snowzhao/2019/12/02/Android-更好用的图片加载库/">





  <title>Android 更好用的图片加载库 | snowzhao博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/snowzhao/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">snowzhao博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">蜕变</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/snowzhao/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/snowzhao/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-标签">
          <a href="/snowzhao/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-分类">
          <a href="/snowzhao/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://vincent_zyt.gitee.io/snowzhao/snowzhao/2019/12/02/Android-更好用的图片加载库/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="snowzhao">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/snowzhao/images/photo.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="snowzhao博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android 更好用的图片加载库</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-02T15:43:43+08:00">
                2019-12-02
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/snowzhao/categories/android/" itemprop="url" rel="index">
                    <span itemprop="name">android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  457
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  2
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>Android项目开发肯定离不开图片的加载，常见的图片加载样式也就圆图、方图、圆角图、单面圆角其他方图；</p>
<p>Android加载图片之前使用imageload加载，现在可能没人使用了吧，应该都使用glide或者Picasso了吧；我自己使用glide封装了一个依赖库，可以实现基本的图片样式加载，先看效果图：</p>
<p><img src="https://img-blog.csdnimg.cn/20191202154028339.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxNzk2NjUx,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p>
<p>看完效果图来看看使用方法吧：</p>
<p>集成方法：<br><code>api &#39;com.bintray.library:image_utils:1.1.1&#39;</code></p>
<p>调用方法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">方形图加载：</span><br><span class="line">ImageUtil.imageLoad(this, TEST_IMAGE, imageView);</span><br><span class="line"></span><br><span class="line"> //加载圆图片</span><br><span class="line"> ImageUtil.imageLoadCircle(this, TEST_IMAGE, imageView03);</span><br><span class="line"></span><br><span class="line"> //加载各种圆角图片====圆角需要传dp值</span><br><span class="line"> ImageUtil.imageLoadFillet(this, TEST_IMAGE, imageView04, num2Dip(this, 20));</span><br><span class="line"> ImageUtil.imageLoadFillet(this, TEST_IMAGE, imageView05, num2Dip(this, 20), ImageFilletDirection.Top);</span><br><span class="line"> ImageUtil.imageLoadFillet(this, TEST_IMAGE, imageView06, num2Dip(this, 20), ImageFilletDirection.Bottom);</span><br><span class="line"> ImageUtil.imageLoadFillet(this, TEST_IMAGE, imageView07,num2Dip(this,20), ImageFilletDirection.Left);</span><br><span class="line"> ImageUtil.imageLoadFillet(this, TEST_IMAGE, imageView08,num2Dip(this,20), ImageFilletDirection.Right);</span><br></pre></td></tr></table></figure>

<p>获取drawable或者bitmap的方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">//通过url获取到Drawable</span><br><span class="line">ImageUtil.imageLoadUrlToDrawable(this, TEST_IMAGE, new ImageUtil.LoadUrlToDrawableListener() &#123;</span><br><span class="line">           @Override</span><br><span class="line">           public void imageDrawable(Drawable drawable) &#123;</span><br><span class="line">               imageView01.setBackgroundDrawable(drawable);</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;);</span><br><span class="line">//通过URL加载获得Bitmap文件</span><br><span class="line"> ImageUtil.imageLoadUrlToBitmap(this, TEST_IMAGE, new ImageUtil.LoadUrlToBitmapListener() &#123;</span><br><span class="line">           @Override</span><br><span class="line">           public void imageBitmap(Bitmap resource) &#123;</span><br><span class="line">               imageView02.setImageBitmap(resource);</span><br><span class="line">           &#125;</span><br><span class="line"></span><br><span class="line">       &#125;);</span><br></pre></td></tr></table></figure>

<p>自定义支持缩放功能的imageView：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">  &lt;com.snow.img.ZoomImageView</span><br><span class="line">         android:id=&quot;@+id/scale_iv&quot;</span><br><span class="line">         android:layout_width=&quot;match_parent&quot;</span><br><span class="line">         android:layout_height=&quot;@dimen/margin_500&quot;</span><br><span class="line">         android:layout_marginTop=&quot;@dimen/margin_020&quot; /&gt;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> //可缩放的图片</span><br><span class="line">  ZoomImageView zoomImageView = findViewById(R.id.scale_iv);</span><br><span class="line">  zoomImageView.setMaxScale(16f);//缩放倍数</span><br><span class="line">//zoomImageView.setCanScale(false);//是否支持缩放</span><br><span class="line"> ImageUtil.imageLoad(this, TEST_IMAGE, zoomImageView);</span><br><span class="line"></span><br><span class="line">直接将数字转化为dp：</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 数字转化为dp</span><br><span class="line">     *</span><br><span class="line">     * @param num</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public int num2Dip(Context mContext, int num) &#123;</span><br><span class="line">        return mContext.getResources().getDimensionPixelSize(R.dimen.base_dip) * num;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>最后可以去看看 ImageUtil 类，很多方法都有重载方法，可以设置默认图片、加载失败、是否使用缓存等功能；</p>
<p>使用的glide版本是com.github.bumptech.glide:glide:4.9.0</p>
<p><a href="https://github.com/zhaoyingtao/ImageUtilsProject" target="_blank" rel="noopener">源码</a></p>
<p>感觉有用给个star支持下！</p>

      
    </div>
    
    
    

 
<div>
  
    <div>
    
        <div style="text-align:center;color: #666;font-size:16px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
  
</div>

    

    

    
    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/snowzhao/tags/android/" rel="tag"># android</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/snowzhao/2019/12/02/js-数据类型转换/" rel="next" title="js 数据类型转换">
                <i class="fa fa-chevron-left"></i> js 数据类型转换
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/snowzhao/2019/12/02/Android-图片和Base64转化，并保存相册/" rel="prev" title="Android 图片和Base64转化，并保存相册">
                Android 图片和Base64转化，并保存相册 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/snowzhao/images/photo.png" alt="snowzhao">
            
              <p class="site-author-name" itemprop="name">snowzhao</p>
              <p class="site-description motion-element" itemprop="description">给自己每天浇点水,迟早会长成一棵大树</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/snowzhao/archives">
              
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/snowzhao/categories/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/snowzhao/tags/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zhaoyingtao" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_31796651" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-stack-overflow"></i>CSDN</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">snowzhao</span>

<!-- 取消英文统计数字
  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">7.4k</span>
  
-->
</div>
<!-- 取消默认 由 hexo 强力驱动 | 主题 next。pisces v5.1.4

  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>



-->



<span class="post-meta-divider"> 坚持 </span>

<span class="post-meta-divider"> | </span>

<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共 7.4k 字</span>
</div>

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/snowzhao/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/snowzhao/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/snowzhao/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/snowzhao/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/snowzhao/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/snowzhao/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/snowzhao/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/snowzhao/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

<script src="/snowzhao/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/snowzhao/live2dw/assets/assets/z16.model.json"},"display":{"position":"right","width":300,"height":500},"mobile":{"show":false},"log":false});</script></body>
</html>
